﻿//--------------------------------------------------------------------------------------------------------------------------------
// <copyright file="Location1D.cs" company="Exul">
//     Copyright (c) Exul. All rights reserved.
// </copyright>
// <author>Exul</author>
//--------------------------------------------------------------------------------------------------------------------------------

namespace ExulLibrary.FiniteElementMethod
{
    using System;

    /// <summary>Represents a location of an element in the one-dimensional space.</summary>
    public sealed class Location1D
    {
        /// <summary>The minimal acceptable size of element.</summary>
        /// <remarks>
        ///     This value represents minimal acceptable difference between
        ///     <see cref="Left"/> and <see cref="Right"/>.
        /// </remarks>
        public const double MinimalSize = 1e-16;

        /// <summary>Initializes a new instance of the <see cref="Location1D"/> class.</summary>
        /// <param name="leftBorder">The left border.</param>
        /// <param name="rightBorder">The right border.</param>
        /// <exception cref="ArgumentOutOfRangeException">
        ///     <paramref name="rightBorder"/> is less than <paramref name="leftBorder"/> or
        ///     greater than it less than <see cref="MinimalSize"/>.
        /// </exception>
        public Location1D(double leftBorder, double rightBorder)
        {
            #if SAFE

            if (rightBorder - leftBorder < 1e-16)
            {
                throw ThrowHelper.InvalidLocation("leftBorder", leftBorder, "rightBorder", rightBorder, MinimalSize);
            }

            #endif

            this.Left = leftBorder;
            this.Right = rightBorder;
        }

        /// <summary>Gets the left border.</summary>
        /// <value>The left border.</value>
        public double Left
        {
            get;
            private set;
        }

        /// <summary>Gets the right border.</summary>
        /// <value>The right border.</value>
        public double Right
        {
            get;
            private set;
        }
    }
}